public class SortTest {
    public static void main(String[] args) {
        int left=0;
        int right=7;
        int[] arr=new int[]{3,4,5,62,25,6,9,23};
        int[] aa=qq(arr,left,right);
        for (int k:aa) {
            System.out.println(k);
        }
    }
    //选择排序
    public static void selectSort(int[] arr){
        for (int i = 0; i < arr.length - 1; i ++) {
            for (int j = i + 1; j < arr.length; j ++) {
                if (arr[i] >= arr[j]) {
                    int min = arr[j];
                    arr[j] = arr[i];
                    arr[i] = min;
                }
            }
        }
        for (int k:arr) {
            System.out.print(k+" ");
        }
    }
    //冒泡排序
    public static void bubbingSort(int[] arr){
        for (int i = 0; i < arr.length - 1; i ++) {
            for (int j = arr.length - 1; j > i; j --) {
                if (arr[j] > arr[j - 1]) {
                    int min = arr[j - 1];
                    arr[j - 1] = arr[j];
                    arr[j] = min;
                }
            }
        }
        for (int k:arr) {
            System.out.println(k);
        }
    }
    //快速排序
    public static int query(int[] arr, int left, int right){
        int p=left;
        int index=p+1;
        for (int i = index; i <= right; i++) {
            if (arr[i] < arr[p]) {
               swap(arr,i,index);
               index++;
            }
        }
        swap(arr,p,index-1);

        return index-1;
    }
    public static void swap(int arr[] ,int i,int j){
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }
    public static int[] qq(int[] arr,int left,int right) {
        if (left<right) {
            int pp=query(arr,left,right);
            qq(arr,left,pp-1);
            qq(arr,pp+1,right);
        }
        return arr;
    }
}
